package com.easy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.Product;
import com.easy.common.bean.UserAccount;
import com.easy.common.service.UserAccountService;
import com.easy.mapper.UserAccountMapper;
import org.springframework.stereotype.Service;
import java.util.List;

/**
* @author ASUS
* @description 针对表【user_account(用户账号认证信息表)】的数据库操作Service实现
* @createDate 2025-09-09 10:27:45
*/
@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount>
    implements UserAccountService{

    @Override
    public UserAccount getUserAccountByUsername(String username) {
        LambdaQueryWrapper<UserAccount> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserAccount::getUsername, username);
        return super.getOne(queryWrapper);
    }


    @Override
    public UserAccount getUserAccountById(Long id) {
        return super.getById(id);
    }

    @Override
    public int addUserAccount(UserAccount userAccount) {
        return super.save(userAccount) ? 1 : 0;
    }

    @Override
    public int updateUserAccount(UserAccount userAccount) {
        return super.updateById(userAccount) ? 1 : 0;
    }

    @Override
    public int deleteUserAccount(Long id) {
        return super.removeById(id) ? 1 : 0;
    }

    @Override
    public int reverseStatus(Long id) {
        UserAccount userAccount = super.getById(id);
        if(userAccount != null){
            userAccount.setStatus(userAccount.getStatus() == 1 ? 0 : 1);
        }
        if(super.removeById(userAccount)){
            return 1;
        }
        return 0;
    }

    @Override
    public List<UserAccount> getAll(UserAccount userAccount) {
        LambdaQueryWrapper<UserAccount> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(UserAccount::getUsername, userAccount.getUsername());
        return super.list(queryWrapper);
    }

    @Override
    public IPage<UserAccount> getPage(UserAccount userAccount, IPage page) {
        LambdaQueryWrapper<UserAccount> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(UserAccount::getUsername, userAccount.getUsername());
        return super.page(page);
    }
}




